import type { UnwrapRef, Ref } from 'vue'

export default function useState<T>(initial: T): [Ref<UnwrapRef<T>>, (next: UnwrapRef<T>) => void] {
  const state = ref(unref(initial))
  const setState = (next: UnwrapRef<T>) => (state.value = unref(next))

  return [state, setState]
}
